<?php
/*
 * kernel/object.document.php
 *
 * This code is distributed and used under the GNU GPL v2 License,
 * please, read file LICENSE, which is situated in root directory,
 * or in "LICENSE" directory with most acceptable translation for you
 *
 * Copyright (C) 2010, Taras Kudla
 *
 * NOTE: Please, be sure that $_SERVER variable is enabled
 *       in your php.ini and required fields are supported
 *       in php + webserver configuration
 *
 */
class gDocument extends gKernel {
   
    private $httpheaders = array(
       "contenttype"=>"text/html",
       "charset"=>null
    );
    /*
     * init
     */
    public function init(){
        $this->httpheaders["charset"]=$this->core->get("charset");
    }
    /*
     * Prepare headers
     */
    public function prepareheaders(){
        # adding http headers
        header("Content-type:".$this->httpheaders["contenttype"]."; charset=".$this->httpheaders["charset"]);

        foreach( $this->httpheaders as $k=>&$v){
            if( $k=="contenttype" || $k=="charset") continue;
            header($v);
        }
    }

    public function sendheaders(){
        # adding http headers
        header("Content-type:".$this->httpheaders["contenttype"]."; charset=".$this->httpheaders["charset"]);

        foreach( $this->httpheaders as $k=>&$v){
            if( $k=="contenttype" || $k=="charset") continue;
            header($v);
        }
    }

    public function gethttplanguage(){
        #
        if( isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
            $httplanguage = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
        }
        return false;
    }

    public function gethttpencoding(){
        #
        if( isset($_SERVER["HTTP_ACCEPT_ENCODING"])){
            $httpencoding = $_SERVER["HTTP_ACCEPT_ENCODING"];
        }
        return false;
    }

    public function gethttprequestmethod(){
        #
        if( isset($_SERVER["REQUEST_METHOD"])){
            $method = $_SERVER["REQUEST_METHOD"];
        }
        return count($_POST)>0?"POST":"GET";
    }

    public function sethttpencoding($encoding){
        #
        if(extension_loaded("zlib"))
            header("Content-encoding:".$encoding);
    }
}